//
//  YDYFenQuViewController.m
//  DY_Bilibili
//
//  Created by 杨德勇 on 2016/10/6.
//  Copyright © 2016年 杨德勇. All rights reserved.
//

#import "YDYFenQuViewController.h"
#import "YDYFenQu.h"
#import "YDYFenQuCell.h"
#import "YDYFenQuLayout.h"

@interface YDYFenQuViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
/** 所有分区的名字 */
@property (nonatomic, strong) NSArray *fenquArray;
/** collectionview */
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@end

static NSString * const ydy_FenquCollectionViewCellIdetifier = @"ydy_FenquCollectionViewCellIdetifier";

@implementation YDYFenQuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupCollectionView];
    
}

-(void)setupCollectionView{
   
    //下面也有弯角了，虽然看不见，但是我不想有
//    self.collectionView.layer.cornerRadius = 8;
    UIEdgeInsets inset = self.collectionView.contentInset;
    inset.bottom += 40;
    self.collectionView.contentInset = inset;
    
    
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([YDYFenQuCell class]) bundle:nil] forCellWithReuseIdentifier:ydy_FenquCollectionViewCellIdetifier];
    self.collectionView.layer.cornerRadius = 8;
    
   
}
-(void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
 

}


#pragma mark -
#pragma mark -

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {

    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return self.fenquArray.count;
//    return 100;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    YDYFenQuCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ydy_FenquCollectionViewCellIdetifier forIndexPath:indexPath];

    cell.fenqu = self.fenquArray[indexPath.item];

    return cell;
}


#pragma mark -
#pragma mark -lazy loading
-(NSArray *)fenquArray{
    if (_fenquArray.count == 0) {
       NSString *filePath =[[NSBundle mainBundle]pathForResource:@"SaCell.plist" ofType:nil];
        NSArray *fileArray = [NSArray arrayWithContentsOfFile:filePath];
        NSMutableArray *tempArray = [NSMutableArray array];
        for (NSDictionary *dict in fileArray) {
            YDYFenQu *fenqu = [YDYFenQu YDYFenQuWithDict:dict];
            [tempArray addObject:fenqu];
        }
        _fenquArray = tempArray;
        
    }
    return _fenquArray;
}


@end
